from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from wecom_practice.base.base_page import BasePage



class AddMemberPage(BasePage):
    # 姓名
    __NAME = By.ID, "username"
    # 帐号
    __ID = By.ID, "memberAdd_acctid"
    # 手机号
    __PHONENUM = By.ID, "memberAdd_phone"
    # 保存按钮
    __SAVE_BTN = By.CSS_SELECTOR, ".qui_btn.ww_btn.js_btn_save"
    def input_member_info(self,mname,mid,phone_num):
        '''
        输入成员信息，点击保存按钮，跳转至通讯录按钮
        :return:
        '''
        # WebDriverWait(self.driver, 10).until(
        #     expected_conditions.invisibility_of_element_located(
        #         (By.XPATH, "//*[@name='username']")
        #     )
        # )
        self.wait_ele_located(*self.__NAME)
        # self.driver.find_element(By.XPATH, "//*[@name='username']").send_keys(mname)
        # self.driver.find_element(By.XPATH, "//*[@name='acctid']").send_keys(mid)
        # self.driver.find_element(By.XPATH, "//*[@name='mobile']").send_keys(phone_num)
        self.ele_sendkeys(*self.__NAME,mname)
        self.ele_sendkeys(*self.__ID,mid)
        self.ele_sendkeys(*self.__PHONENUM,phone_num)
        # driver.find_element(By.XPATH,("//a[text()='保存']/[0]")[0]).click()
        # 使用JS方式来保存按钮
        # save_btn = self.driver.find_element(By.CSS_SELECTOR, ".qui_btn.ww_btn.js_btn_save")
        # self.driver.execute_script("arguments[0].click();", save_btn)
        save_btn=self.find_ele(*self.__SAVE_BTN)
        self.click_ele_by_js(save_btn)
        from wecom_practice.page.contact_page import ContactPage
        return ContactPage(self.driver)